#include "mainwindow.h"

#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QSharedMemory>
#include <QMessageBox>
#include <QSettings>
#include "InitForm/initwidget.h"
#include "Action/actionform.h"
#include "SaveLog/savelog.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);


    QString appPath = a.applicationDirPath();
    QTranslator transQt;
    transQt.load("qt_zh_CN", appPath);
    a.installTranslator(&transQt);
    QTranslator transDI;
    transDI.load("Mz_Wood_zh_CN", appPath);
    a.installTranslator(&transDI);

    a.setOrganizationName("SXTech");
    a.setApplicationName("Mz_Wood");
    QSettings::setDefaultFormat(QSettings::IniFormat);

    // ///设置是否开启日志上下文打印比如行号、函数等
    // SaveLog::Instance()->setUseContext(true);
    // ///设置文件存储目录
    // SaveLog::Instance()->setPath(qApp->applicationDirPath() + "/log");
    // SaveLog::Instance()->deleteLocalLog();
    // SaveLog::Instance()->start();
    // SaveLog::Instance()->setMaxSize(1024*10);


    /// 检测是否重复运行程序
    static QSharedMemory *sharMemory = new QSharedMemory("Mz_Wood.exe");
    if(sharMemory->attach())
    {
        QMessageBox::information(NULL,"Warning",QObject::tr("Application is running!"));
        return 0;
    }
    sharMemory->create(1);

    InitWidget w;
    w.hide();

    ActionForm s;
    s.show();

    QObject::connect(&s,&ActionForm::done,&w,&InitWidget::show);
    MainWindow m;

    w.addWidget(&m);

    QObject::connect(&w,&InitWidget::appQuit,&m,&MainWindow::appQuit);
    QObject::connect(&s,&ActionForm::appQuit,&m,&MainWindow::appQuit);
    return a.exec();
}
